package cn.exrick.controller;

import cn.exrick.pojo.common.DataTablesResult;
import cn.exrick.service.FeedbackCatService;
import cn.exrick.service.FeedbackService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 反馈管理
 */
@RestController
@Api(description= "反馈管理")
public class FeedbackController {

    @Autowired
    private FeedbackService feedbackService;

    @RequestMapping(value = "/feedback/list",method = RequestMethod.GET)
    @ApiOperation(value = "分页多条件搜索获取反馈列表")
    public DataTablesResult getFeedbackList(int draw, int start, int length, String searchKey, Integer feedbackCatId,
                                          String minDate, String maxDate,
                                          @RequestParam("search[value]") String search, @RequestParam("order[0][column]") int orderCol,
                                          @RequestParam("order[0][dir]") String orderDir){

        //获取客户端需要排序的列
        String[] cols = {"id", "member_name", "content", "image", "feedback_cat_id", "created"};
        String orderColumn = cols[orderCol];
        //默认排序列
        if(orderColumn == null) {
            orderColumn = "created";
        }
        //获取排序方式 默认为desc(asc)
        if(orderDir == null) {
            orderDir = "desc";
        }
        if(!search.isEmpty()){
            searchKey=search;
        }
        DataTablesResult result = feedbackService.getFeedbackPage(draw, start, length, searchKey, feedbackCatId, minDate, maxDate, orderColumn, orderDir);
        return result;
    }
}
